package com.mmp.main.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.mmp.common.util.SearchRequired;

/**
 * The persistent class for the hospital_device database table.
 *
 */
@Entity
@Table(name = "hospital_device")
@NamedQuery(name = "HospitalDevice.findAll", query = "SELECT h FROM HospitalDevice h ORDER BY h.name")
public class HospitalDevice implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	private Integer id;

	@ManyToOne
	@JoinColumn(name = "site_id")
	private Site site;

	@ManyToOne
	@JoinColumn(name = "hosp_id")
	private Hospital hospital;

	@ManyToOne
	@JoinColumn(name = "department_id")
	@NotFound(action = NotFoundAction.IGNORE)
	@SearchRequired(isObject = true)
	private HospitalDepartment hospitalDepartment;

	@SearchRequired
	private String code;

	@Column(name = "serial_no")
	@SearchRequired
	private String serialNo;

	private String name;

	@Column(name = "manufacturer_name")
	private String manufacturerName;

	private String model;

	@ManyToOne
	@JoinColumn(name = "category_id")
	@SearchRequired(isObject = true)
	private LookupDeviceCategory category;

	@Column(name = "agent_name")
	private String agentName;

	private String subcontractor;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "operation_date")
	private Date operationDate;

	@Column(name = "ta3mid_no")
	private String ta3midNo;

	private Float price;

	@Column(name = "within_warranty")
	@SearchRequired
	private Boolean withinWarranty;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "warranty_expire_date")
	private Date warrantyExpireDate;

	@Column(name = "within_contract")
	@SearchRequired
	private Boolean withinContract;

	@Column(name = "added_from_another_location")
	private Boolean addedFromAnotherLocation;

	@Column(name = "location_name")
	private String locationName;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "add_date")
	private Date addDate;

	@Column(name = "pm_annual_visits_no")
	private Integer pmAnnualVisitsNo;

	@Column(name = "pm_visits_months")
	private String pmVisitsMonths;

	@Column(name = "previous_expenses")
	private Float previousExpenses;

	@Column(name = "other_attachments")
	private String otherAttachments;

	@ManyToOne
	@JoinColumn(name = "created_by")
	private User createdBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "created_in")
	private Date createdIn;

	@ManyToOne
	@JoinColumn(name = "last_modified_by")
	private User lastModifiedBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "last_modified_in")
	private Date lastModifiedIn;

	private Integer status;

	@OneToOne(mappedBy = "hospitalDevice")
	private HospitalDeviceScrappingInfo scrappingInfo;

	@OneToOne(mappedBy = "hospitalDevice")
	private HospitalDeviceTransferringInfo transferringInfo;

	@LazyCollection(LazyCollectionOption.FALSE)
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "hospitalDevice", orphanRemoval = true)
	private List<HospitalDeviceAccessory> hospitalDeviceAccessories;

	public HospitalDevice() {
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Site getSite() {
		return site;
	}

	public void setSite(Site site) {
		this.site = site;
	}

	public Hospital getHospital() {
		return hospital;
	}

	public void setHospital(Hospital hospital) {
		this.hospital = hospital;
	}

	public HospitalDepartment getHospitalDepartment() {
		return hospitalDepartment;
	}

	public void setHospitalDepartment(HospitalDepartment hospitalDepartment) {
		this.hospitalDepartment = hospitalDepartment;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getSerialNo() {
		return serialNo;
	}

	public void setSerialNo(String serialNo) {
		this.serialNo = serialNo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getManufacturerName() {
		return manufacturerName;
	}

	public void setManufacturerName(String manufacturerName) {
		this.manufacturerName = manufacturerName;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public LookupDeviceCategory getCategory() {
		return category;
	}

	public void setCategory(LookupDeviceCategory category) {
		this.category = category;
	}

	public String getAgentName() {
		return agentName;
	}

	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}

	public String getSubcontractor() {
		return subcontractor;
	}

	public void setSubcontractor(String subcontractor) {
		this.subcontractor = subcontractor;
	}

	public Date getOperationDate() {
		return operationDate;
	}

	public void setOperationDate(Date operationDate) {
		this.operationDate = operationDate;
	}

	public String getTa3midNo() {
		return ta3midNo;
	}

	public void setTa3midNo(String ta3midNo) {
		this.ta3midNo = ta3midNo;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public Boolean getWithinWarranty() {
		return withinWarranty;
	}

	public void setWithinWarranty(Boolean withinWarranty) {
		this.withinWarranty = withinWarranty;
	}

	public Date getWarrantyExpireDate() {
		return warrantyExpireDate;
	}

	public void setWarrantyExpireDate(Date warrantyExpireDate) {
		this.warrantyExpireDate = warrantyExpireDate;
	}

	public Boolean getWithinContract() {
		return withinContract;
	}

	public void setWithinContract(Boolean withinContract) {
		this.withinContract = withinContract;
	}

	public Boolean getAddedFromAnotherLocation() {
		return addedFromAnotherLocation;
	}

	public void setAddedFromAnotherLocation(Boolean addedFromAnotherLocation) {
		this.addedFromAnotherLocation = addedFromAnotherLocation;
	}

	public String getLocationName() {
		return locationName;
	}

	public void setLocationName(String locationName) {
		this.locationName = locationName;
	}

	public Date getAddDate() {
		return addDate;
	}

	public void setAddDate(Date addDate) {
		this.addDate = addDate;
	}

	public Integer getPmAnnualVisitsNo() {
		return pmAnnualVisitsNo;
	}

	public void setPmAnnualVisitsNo(Integer pmAnnualVisitsNo) {
		this.pmAnnualVisitsNo = pmAnnualVisitsNo;
	}

	public String getPmVisitsMonths() {
		return pmVisitsMonths;
	}

	public void setPmVisitsMonths(String pmVisitsMonths) {
		this.pmVisitsMonths = pmVisitsMonths;
	}

	public Float getPreviousExpenses() {
		return previousExpenses;
	}

	public void setPreviousExpenses(Float previousExpenses) {
		this.previousExpenses = previousExpenses;
	}

	public String getOtherAttachments() {
		return otherAttachments;
	}

	public void setOtherAttachments(String otherAttachments) {
		this.otherAttachments = otherAttachments;
	}

	public User getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}

	public Date getCreatedIn() {
		return createdIn;
	}

	public void setCreatedIn(Date createdIn) {
		this.createdIn = createdIn;
	}

	public User getLastModifiedBy() {
		return lastModifiedBy;
	}

	public void setLastModifiedBy(User lastModifiedBy) {
		this.lastModifiedBy = lastModifiedBy;
	}

	public Date getLastModifiedIn() {
		return lastModifiedIn;
	}

	public void setLastModifiedIn(Date lastModifiedIn) {
		this.lastModifiedIn = lastModifiedIn;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public HospitalDeviceScrappingInfo getScrappingInfo() {
		return scrappingInfo;
	}

	public void setScrappingInfo(HospitalDeviceScrappingInfo scrappingInfo) {
		this.scrappingInfo = scrappingInfo;
	}

	public HospitalDeviceTransferringInfo getTransferringInfo() {
		return transferringInfo;
	}

	public void setTransferringInfo(HospitalDeviceTransferringInfo transferringInfo) {
		this.transferringInfo = transferringInfo;
	}

	public List<HospitalDeviceAccessory> getHospitalDeviceAccessories() {
		return this.hospitalDeviceAccessories;
	}

	public void setHospitalDeviceAccessories(List<HospitalDeviceAccessory> hospitalDeviceAccessories) {
		this.hospitalDeviceAccessories = hospitalDeviceAccessories;
	}

	public HospitalDeviceAccessory addHospitalDeviceAccessory(HospitalDeviceAccessory hospitalDeviceAccessory) {
		getHospitalDeviceAccessories().add(hospitalDeviceAccessory);
		hospitalDeviceAccessory.setHospitalDevice(this);

		return hospitalDeviceAccessory;
	}

	public HospitalDeviceAccessory removeHospitalDeviceAccessory(HospitalDeviceAccessory hospitalDeviceAccessory) {
		getHospitalDeviceAccessories().remove(hospitalDeviceAccessory);
		hospitalDeviceAccessory.setHospitalDevice(null);

		return hospitalDeviceAccessory;
	}

}
